package com.awakening.service.impl;

import com.awakening.dao.Impl.UserDaoImpl;
import com.awakening.dao.UserDao;
import com.awakening.pojo.User;
import com.awakening.service.UserService;
import com.awakening.utils.MailUtils;

import java.sql.SQLException;

/**
 * 用户Service实现类
 * @Author:AwakeningCode
 * @Date: Created in 17:57 2018\1\22 0022
 */
public class UserServiceImpl implements UserService{
    //用户注册方法
    public void regist(User user)  throws Exception {
        //将数据存入数据库
        UserDao userDao = new UserDaoImpl();
        userDao.regist(user);
        //发送一封激活邮件
        MailUtils.sendMail(user.getEmail(),user.getCode());
    }

    public User findByCode(String code) throws Exception{
        UserDao userDao = new UserDaoImpl();
        return userDao.findByCode(code);
    }

    public void update(User user) throws Exception {
        UserDao userDao = new UserDaoImpl();
        userDao.update(user);
    }
}
